package com.ss.android.lockscreen.activity.lock;

import android.os.SystemClock;
import android.support.v4.view.VelocityTrackerCompat;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewTreeObserver;

import com.ss.android.lockscreen.views.c;

final class bb implements ViewTreeObserver.OnPreDrawListener {
    private final LockScreenActivity a;

    bb(LockScreenActivity arg1) {
        this.a = arg1;

    }

    public final boolean onPreDraw() {
        float v1_1;
        float v0_4;
        Object v1;
        float v3;
        float v4;
        int v5;
        float v2_1;
        c v9;
        int v0_1;
        float v11 = 1f;
        LockScreenActivity.a(this.a).getViewTreeObserver().removeOnPreDrawListener(((ViewTreeObserver.OnPreDrawListener) this));
        if (LockScreenActivity.m(this.a) == null) {
            return false;
        }

        if (LockScreenActivity.m(this.a).d() <= 0) {
            return false;
        }

        if (LockScreenActivity.a(this.a) == null) {
            return false;
        }

        try {
            c v10 = LockScreenActivity.a(this.a);
            if (((ViewPager) v10).mIsBeingDragged) {
                v0_1 = 0;
            } else {
                ((ViewPager) v10).mFakeDragging = true;
                ((ViewPager) v10).setScrollState(1);
                ((ViewPager) v10).mLastMotionX = 0f;
                ((ViewPager) v10).mInitialMotionX = 0f;
                if (((ViewPager) v10).mVelocityTracker == null) {
                    ((ViewPager) v10).mVelocityTracker = VelocityTracker.obtain();
                } else {
                    ((ViewPager) v10).mVelocityTracker.clear();
                }

                long v0_2 = SystemClock.uptimeMillis();
                MotionEvent v2 = MotionEvent.obtain(v0_2, v0_2, 0, 0f, 0f, 0);
                ((ViewPager) v10).mVelocityTracker.addMovement(v2);
                v2.recycle();
                ((ViewPager) v10).mFakeDragBeginTime = v0_2;
                v0_1 = 1;
            }

            if (v0_1 == 0) {
                return false;
            }

            v9 = LockScreenActivity.a(this.a);
            if (!((ViewPager) v9).mFakeDragging) {
                throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
            }

            if (((ViewPager) v9).mAdapter != null) {
                ((ViewPager) v9).mLastMotionX += v11;
                v2_1 = (((float) ((ViewPager) v9).getScrollX())) - v11;
                v5 = ((ViewPager) v9).getClientWidth();
                v4 = (((float) v5)) * ((ViewPager) v9).mFirstOffset;
                v3 = (((float) v5)) * ((ViewPager) v9).mLastOffset;
                Object v0_3 = ((ViewPager) v9).mItems.get(0);
                v1 = ((ViewPager) v9).mItems.get(((ViewPager) v9).mItems.size() - 1);
                if (((ViewPager.ItemInfo) v0_3).position != 0) {
                    v0_4 = ((ViewPager.ItemInfo) v0_3).offset * (((float) v5));
                } else {
                    v0_4 = v4;
                }

                try {
                    label_88:
                    if (((ViewPager.ItemInfo) v1).position != ((ViewPager) v9).mAdapter.getCount() - 1) {
                        v1_1 = ((ViewPager.ItemInfo) v1).offset * (((float) v5));
                    } else {
                        v1_1 = v3;
                    }
                } catch (Exception v0) {
                    return false;
                }
                if (v2_1 >= v0_4) {
                    v0_4 = v2_1 > v1_1 ? v1_1 : v2_1;
                }
                ((ViewPager) v9).mLastMotionX += v0_4 - (((float) (((int) v0_4))));
                ((ViewPager) v9).scrollTo(((int) v0_4), ((ViewPager) v9).getScrollY());
                ((ViewPager) v9).pageScrolled(((int) v0_4));
                MotionEvent v0_5 = MotionEvent.obtain(((ViewPager) v9).mFakeDragBeginTime, SystemClock.uptimeMillis(), 2, ((ViewPager) v9).mLastMotionX, 0f, 0);
                ((ViewPager) v9).mVelocityTracker.addMovement(v0_5);
                v0_5.recycle();
            }
            c v0_6 = LockScreenActivity.a(this.a);
            if (!((ViewPager) v0_6).mFakeDragging) {
                throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
            }

            if (((ViewPager) v0_6).mAdapter != null) {
                VelocityTracker v1_2 = ((ViewPager) v0_6).mVelocityTracker;
                v1_2.computeCurrentVelocity(1000, ((float) ((ViewPager) v0_6).mMaximumVelocity));
                int v1_3 = ((int) VelocityTrackerCompat.getXVelocity(v1_2, ((ViewPager) v0_6).mActivePointerId));
                ((ViewPager) v0_6).mPopulatePending = true;
                int v2_2 = ((ViewPager) v0_6).getClientWidth();
                int v3_1 = ((ViewPager) v0_6).getScrollX();
                ViewPager.ItemInfo v4_1 = ((ViewPager) v0_6).infoForCurrentScrollPosition();
                ((ViewPager) v0_6).setCurrentItemInternal(((ViewPager) v0_6).determineTargetPage(v4_1.position, ((((float) v3_1)) / (((float) v2_2)) - v4_1.offset) / v4_1.widthFactor, v1_3, ((int) (((ViewPager) v0_6).mLastMotionX - ((ViewPager) v0_6).mInitialMotionX))), true, true, v1_3);
            }

            ((ViewPager) v0_6).endDrag();
            ((ViewPager) v0_6).mFakeDragging = false;
            return false;
        } catch (Exception v0) {
            return false;
        }
    }
}

